#include <iostream> 
#include <map>
#include <string>
using namespace std;

int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	string s;
	int shiji,kaoshi;
	map<int,pair<string,int>> mp;
	for(int i=0; i<n; i++){
		cin >> s >> shiji >> kaoshi;
		cout << s << shiji << kaoshi << endl;
		mp[shiji] = make_pair(s,kaoshi);
	} 
	int m,t;
	cin >> m;
	for(int i=0; i<m; i++){
		cin >> t;
		cout << mp[t].first << " " << mp[t].second << endl;
	}
	return 0;
}
